package ru.futurelink.moneyorganizer.widgets;

import java.util.ArrayList;

import android.content.Context;
import android.util.FloatMath;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class MOGraphicTable extends LinearLayout {
	private Integer 						mItemHeight = 49;
	private Integer							mItemWidth = 100;

	private ArrayList<ArrayList<TextView>>	mItems = null;
	private ArrayList<LinearLayout>			mRowLayouts = null;
	private Context							mContext;
	
	public MOGraphicTable(Context context) {
		super(context);
		mContext = context;
		
		setOrientation(LinearLayout.VERTICAL);
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
		setLayoutParams(params);
		setBackgroundColor(0xffaabbcc);
				
		mItems = new ArrayList<ArrayList<TextView>>(); 
		mRowLayouts = new ArrayList<LinearLayout>();
	}
	
	public void setItemHeight(Integer height) {
		mItemHeight = height;
	}

	public void setItemWidth(Integer width) {
		mItemWidth = width;
	}
	
	public void setRowData(Integer rowIndex, ArrayList<String> data) {
		LinearLayout layB = new LinearLayout(mContext);
		layB.setOrientation(LinearLayout.HORIZONTAL);
		layB.setBackgroundColor(0xffaabbcc);
		for (int j = 0; j < data.size(); j++) {
			TextView a = new TextView(mContext);
			a.setHeight(mItemHeight-1);
			a.setText(data.get(j));
			a.setBackgroundColor(0xffffffff);
			a.setGravity(Gravity.CENTER);
			a.setWidth(mItemWidth);
			a.setBackgroundColor(0xff000000+
					0x00010101*(int)Math.round(Math.random()*255));
			LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params.setMargins(1, 0, 0, 1);
			layB.addView(a, params);
			mItems.get(rowIndex).add(a);
		}
		addView(layB);

		mRowLayouts.set(rowIndex, layB);
	}
	
	public void addRow() {
		mItems.add(new ArrayList<TextView>());
		mRowLayouts.add(null);
	}
	
	public void refresh() {
		
	}

}
